//
//  YBHomeBannerNewsViewController.m
//  ZhongWangYuanApp
//
//  Created by apple on 2019/5/9.
//  Copyright © 2019 apple. All rights reserved.
//

#import "YBHomeBannerNewsViewController.h"
#import "YBBannerNewsModel.h"

@interface YBHomeBannerNewsViewController ()<UIWebViewDelegate>

@property (nonatomic , strong) UIWebView * webView;

@property (nonatomic , strong) YBBannerNewsModel * model;

@end

@implementation YBHomeBannerNewsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.ybTitleString = @"新闻";
    [self.view addSubview:self.webView];
    [self initDataSource];
}

-(void)initDataSource{
    [YJProgressHUD showMessage:@"加载中..." duration:10.f view:self.view];
    [YBRequestManager request_homeBannerNewsWithIdString:self.idString successBlock:^(id object) {
        [YJProgressHUD hide];
        if ([object[@"code"] integerValue] == 1) {
            if ([object[@"data"] isKindOfClass:[NSArray class]]) {
                self.model = [YBBannerNewsModel yy_modelWithJSON:object[@"data"][0]];
                if (self.model) {
                    [self.webView loadHTMLString:self.model.content baseURL:nil];
                    self.ybTitleString = self.model.title;
                }
            }
        }
        else{
            [YJProgressHUD showMsgWithoutView:@"获取失败"];
        }
    } failBlock:^(id object) {
        [YJProgressHUD hide];
        [YJProgressHUD showMsgWithoutView:@"获取失败"];
    }];
}


-(void)webViewDidFinishLoad:(UIWebView *)webView
{
//    NSString *str = @"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '200%'";
//    [webView stringByEvaluatingJavaScriptFromString:str];
}


- (UIWebView *)webView{
    if (_webView == nil){
        
        CGRect rect = CGRectMake(0, LP_NavViewHeight, [UIScreen zj_screenWith], [UIScreen zj_screenHeight] - LP_NavViewHeight);
        _webView = [[UIWebView alloc]initWithFrame:rect];
        _webView.delegate = self;
        _webView.scalesPageToFit=YES;
        _webView.dataDetectorTypes = UIDataDetectorTypePhoneNumber | UIDataDetectorTypeLink | UIDataDetectorTypeShipmentTrackingNumber | UIDataDetectorTypeFlightNumber | UIDataDetectorTypeLookupSuggestion;
        _webView.backgroundColor = [UIColor clearColor];
        [_webView setOpaque:YES];
    }
    return _webView;
}

@end
